using UnityEngine;
using UnityEditor;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public class ParseRigidbody : ParseObjectHandle<Rigidbody>
{
    public override void Prase(ExportSetting ExportSetting, Rigidbody obj, JArray jArray)
    {
        var ccRigidbody = ExportSetting.CocosObjectConfig["cc.RigidBody"].DeepClone();
        if (obj.isKinematic)
        {
            ccRigidbody["_type"] = 4;
        }
        else
        {
            ccRigidbody["_type"] = 1;
        }
        ccRigidbody["_mass"] = obj.mass;
        ccRigidbody["_linearDamping"] = obj.drag;
        ccRigidbody["_angularDamping"] = obj.angularDrag;
        ccRigidbody["_linearFactor"] = AssetHelper.TransforCCObject(Vector3.one);
        ccRigidbody["_angularFactor"] = AssetHelper.TransforCCObject(Vector3.one);
        if ((obj.constraints & RigidbodyConstraints.FreezePositionX) > 0)
        {
            ccRigidbody["_linearFactor"]["x"] = 0;
        }
        if ((obj.constraints & RigidbodyConstraints.FreezePositionY) > 0)
        {
            ccRigidbody["_linearFactor"]["y"] = 0;
        }
        if ((obj.constraints & RigidbodyConstraints.FreezePositionZ) > 0)
        {
            ccRigidbody["_linearFactor"]["z"] = 0;
        }
        if ((obj.constraints & RigidbodyConstraints.FreezeRotationX) > 0)
        {
            ccRigidbody["_angularFactor"]["x"] = 0;
        }
        if ((obj.constraints & RigidbodyConstraints.FreezeRotationY) > 0)
        {
            ccRigidbody["_angularFactor"]["y"] = 0;
        }
        if ((obj.constraints & RigidbodyConstraints.FreezeRotationZ) > 0)
        {
            ccRigidbody["_angularFactor"]["z"] = 0;
        }
        ccRigidbody["_useGravity"] = obj.useGravity;
        //ccRigidbody[""]

        jArray.Add(ccRigidbody);
    }
}